app.controller('echartsCtrl',['$scope','homeService',function ($scope,homeService) {
	// var data = {"results":1,"items":[{"SPI":6.666,"LOGIN_RATE":91.52,"CHECK_RATE":95.14,"JN_RATE":1.48}],"success":true}
	var data = JSON.parse(homeService.getData());
	  $scope.chartParam1 = {index:data.data.items[0].SPI,title:'综合预警指数'};

	 console.log(data);
    // $scope.$on('chartsData',function(event,data){
     //    $scope.chartParam1 = {'index':data.items[0].SPI,'title':'综合预警指数'};
     //    // $scope.$parent.chartParam1 = abc;
     //    // $scope.$$childHead.chartParam1 = abc;
     //    //$scope.$apply();
    // })

}]).directive('line', function(){
    return {  
        scope: {
        	id:'@',
            chartParam1:'='
        },
        restrict: 'E',  
        template: '<div style="width:140%;height:100%;"></div>',
        replace: true,  
        link: function($scope, element, attrs, controller) {  
        	// console.log($scope.$parent);
        	var option = {
                series: [
                {
                    axisLine: {
                       show: true,
                       lineStyle: {
                             color: [
                                       [0.33, '#B5D7A5'],
                                       [0.5, '#FFA27E'],
                                       [0.67, '#F7F3AA'],
                                       [1.0, '#F05436']
                                     ],
                             width: 13
                        }
                    },
                    axisTick: {
                    	show: true
                    },
                    axisLabel: {
                    	distance: 6,
                    	textStyle: {
                    		color: 'auto'
                    	}
                    },
                	splitLine: { //分割线样式 
                    	length: 13,
                    	lineStyle: {
                    		width: 1
                    	}
                  	},
                	itemStyle: {
                    	normal: {
                    	color: '#7A9BD1'
                    }
                 },
                 radius: '100%',
                 pointer: {
                    width: 6
                },
                title: {
                    textStyle: {
                    fontWeight: '',
                    fontSize: 13,
                    color: '#7A9BD1'
                },
                offsetCenter: [0, '85%']
            },
            detail: {
                textStyle: {
                fontWeight: '',
                fontSize: 13,
                color: '#7A9BD1'
            },
            offsetCenter: [0, '50%'],
            formatter: '{value}'
        },
        name: '米类仪表盘',
        type: 'gauge',
        show: false,
        splitNumber: 10,
        min: 0,
        max: 30,
        data: [{
             value:$scope.$parent.chartParam1.index,
            // value:6.66,
            name: '综合预警指数'
        }]
    }]
}
            var myChart = echarts.init(document.getElementById($scope.id),'macarons');  
            myChart.setOption(option);  
        }
    };  
});